<?php

/**
 * 便利100 
 * ============================================================================
 * * 版权所有 一直奋斗的PHP开发工程师，并保留所有权利。
 * 网站地址: http://www.dengwz7788.com；
 * ----------------------------------------------------------------------------
 * 这是一个自由软件！你可以在任何情况下对程序代码进行修改和
 * 使用；允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: summer $
 * $Id: locate.php 2013-4-23 summer$
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

//获取商店
if(!empty($_GET))
{
   //构造处理类
   setcookie("region_id", $_GET["region_id"], time()+3600*24*7);
     //数据处理成功
   ecs_header("Location: index.php\n");
   exit;

}

/**
 * 获得指定国家的所有省份
 */
function get_locate($type = 0, $parent = 0)
{
    $sql = 'SELECT region_id, region_name FROM ' . $GLOBALS['ecs']->table('region') .
            " WHERE region_type = '$type' AND parent_id = '$parent'";

    return  $GLOBALS['db']->getAll($sql);
}

/**
 * 获得所有四级区域列表
 */
function get_locate_discrict($type = 0)
{
    $sql = 'SELECT region_id, region_name FROM ' . $GLOBALS['ecs']->table('region') .
            " WHERE region_type = '$type'";

    return  $GLOBALS['db']->getAll($sql);
}

$smarty->assign('country_list',       get_locate());
$smarty->assign('province_list',       get_locate(1,13));
$smarty->assign('city_list',       get_locate(2,0));
$smarty->assign('district_list',       get_locate_discrict(3));
$smarty->assign('shop_name',     $GLOBALS['_CFG']['shop_name']);
$smarty->assign('copyright',     sprintf($GLOBALS['_LANG']['copyright'], date('Y'), $GLOBALS['_CFG']['shop_name']));
if (!empty($GLOBALS['_CFG']['search_keywords']))
    {
        $searchkeywords = explode(',', trim($GLOBALS['_CFG']['search_keywords']));
    }
    else
    {
        $searchkeywords = array();
    }
    $smarty->assign('searchkeywords', $searchkeywords);

$smarty->display('locate.dwt');


?>